package com.ztmg.common.util;

import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;

/**
 * 
 * @desc [字符串相关的工具类]
 * @author lishibin
 * @datetime 2017-11-1 上午11:31:19
 */
public class StringUtil {

	/**
	 * 判断字符串是否为空 
	 * @param str
	 * @return 字符串为空返回true否则false
	 */
	public static boolean isEmpty(String str) {
		if (str == null || "".equals(str.trim()) ||"null".equals(str.trim())) {
			return true;
		}
		return false;
	}
	
	/**
	 *按参数名称a-z排序,遇到空值的参数不参加签名。
	 */
	public static String createSign(SortedMap<String, String> packageParams) {
		StringBuffer sb = new StringBuffer();
		Set es = packageParams.entrySet();
		int i=0;
		Iterator it = es.iterator();
		while (it.hasNext()) {
			Map.Entry entry = (Map.Entry) it.next();
			String k = (String) entry.getKey();
			String v = (String) entry.getValue();
			if(i!=0)
			{
				sb.append("&"+k + "=" + v);
			}
			else
			{
				sb.append(k + "=" + v);
			}
			i++;
		}
		return sb.toString();

	}
	/**
	 * 转“1，2，3”类的字符串到（‘1’，‘2’，‘3’）
	 */
	public  static String   toSqlString(String  a)
	{
		StringBuilder orderIdsParams = new StringBuilder();
		orderIdsParams.append("(");
         if(null!=a && !a.trim().equals(""))
         {


				 String[] idArray = a.split(",");
				 for (int i=0;i<idArray.length;i++)
				 {

					 orderIdsParams.append("\"");
					 orderIdsParams.append(idArray[i]);
					 orderIdsParams.append("\"");
					 orderIdsParams.append(",");
				 }
				 orderIdsParams.delete(orderIdsParams.length()-1,orderIdsParams.length());

			 orderIdsParams.append(")");
		 }
		 else
		 	{
		 		return "";
			}
			return orderIdsParams.toString();
	}


}
